home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-serious-
/
programming
/
arexx
/
parsevariables
/
parsevariables.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1999-09-06
|
3KB
|
103 lines
/*
$VER: ParseVariables() v1.0 (14 Aug 1999) © Ron Goertz (goertz@earthlink.net)
The ParseVariables() routine takes an error line (usually an
equation) as its argument and determines the values of any
variables in that line. This can greatly speed up debugging by
not having to enter specific debugging information lines for each
suspect line.
* Functions (eg, left(), strip(), etc) are not included in the printout
* All uninitialized variables will be put in a single line labeled LIT
* All variables, including those used in compound variables, will have
their current value printed
* Variables will only be listed once
Because the routine must be able to query the values of the variables in
the suspect line, this routine can't be made a PROCEDURE. All variables
used by the routine, then, start with PV_ to (hopefully) prevent over-writing
variables used by the main program.
To see the results of this macro, simply open a shell and type
rx <path>ParseVariables.rexx
Try changing the assigned variables and the "dummy" line to see other results.
Please let me (Ron Goertz <goertz@earthlink.net>) know if this function is of
use to you, doesn't work for you, or if you have ideas on how to improve it.
This routine was developed for use in my calendar creator, FWCalendar: THE
calendar creator for Final Writer and PageStream.
*/
options results
signal on syntax
a = 'Hello'
b = 6
c = 3
d = 2
Stem. = 'Variable'
dummy = strip(left(substr(Stem.c.d, b, b/3), b*z))
exit
/******* Syntax () Subroutine ***********/
Syntax:
signal off syntax
call writeln(stdout, 'Error 'RC' ('errortext(RC)')')
call writeln(stdout, 'Line 'SIGL': 'strip(SourceLine(SIGL)))
call writeln(stdout, ParseVariables(SourceLine(SIGL)))
exit
/**/
/******* ParseVariables (PV) Subroutine ***********/
ParseVariables:
parse arg PV_Line
PV_String = translate(PV_Line,,'=(+-*/,)"'||"'",' ')
PV_VarString = ''
PV_Var. = '00'x
PV_LongVar = 0
PV_LIT = ''
PV_Count = 0
do PV_i = 1 to words(PV_String)
PV_Word = word(PV_String, PV_i)
if pos(PV_Word'(', PV_Line) > 0 then iterate
if datatype(PV_Word) == 'CHAR' then do
if symbol(PV_Word) == 'LIT' then PV_LIT = PV_LIT''PV_Word', '
if symbol(PV_Word) == 'VAR' then do
PV_LongVar = max(PV_LongVar, length(PV_Word) + 2)
if PV_Var.PV_Word == '00'x then do
PV_Count = PV_Count + 1
PV_Var.PV_Count = PV_Word
PV_Var.PV_Word = value(PV_Word)
end
if pos('.', PV_Word) > 0 then do
PV_CompoundParts = subword(translate(PV_Word,,'.', ' '), 2)
do PV_j = 1 to words(PV_CompoundParts)
PV_Subword = word(PV_CompoundParts, PV_j)
if PV_Var.PV_SubWord == '00'x then do
PV_Count = PV_Count + 1
PV_Var.PV_Count = PV_SubWord
if symbol(PV_Subword) == 'LIT' then PV_Var.PV_SubWord = 'LIT'
else PV_Var.PV_SubWord = value(PV_SubWord)
end
end
end
end
end
end
do PV_i = 1 to PV_Count
PV_Word = PV_Var.PV_i
PV_VarString = PV_VarString''right(PV_Word, PV_LongVar)' = 'PV_Var.PV_Word||'0a'x
end
if PV_LIT ~= '' then PV_VarString = right('LIT', PV_LongVar)' = 'strip(PV_LIT, 'B', ' ,')||'0a'x||PV_VarString
return PV_VarString
/**/